package com.liukai.bishe.ui.adapter;

import android.app.Activity;
import android.content.Context;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.view.ViewGroup;

import com.liukai.bishe.R;
import com.liukai.bishe.presenter.userPresenter.IUpdateUserInfoPresenter;
import com.liukai.bishe.ui.viewHolder.BaseViewHolder;
import com.liukai.bishe.ui.viewHolder.UserInfoViewHolder;
import com.liukai.bishe.ui.viewHolder.listener.UserInfoOnClickListener;
import com.liukai.bishe.ui.viewHolder.listener.impl.UserInfoOnClickListenerImpl;
import com.liukai.bishe.utils.Constants;
import com.liukai.bishe.utils.ToastUtil;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class UserInfoAdapter extends RecyclerView.Adapter<BaseViewHolder> {

    private Context mContext;
    private List<String> mUserInfoList;
    private final UserInfoOnClickListener mUserInfoOnClickListener;

    public UserInfoAdapter(Context context, List<String> userInfoList, Activity activity, IUpdateUserInfoPresenter iUpdateUserInfoPresenter) {
        this.mContext = context;
        this.mUserInfoList = userInfoList;
        mUserInfoOnClickListener = new UserInfoOnClickListenerImpl(mContext,activity,iUpdateUserInfoPresenter);
        for (String s : mUserInfoList) {
            ToastUtil.log(mContext,"标题========================="+s);
            ToastUtil.log(mContext,"内容========================="+Constants.getUserInfoMap().get(s));
        }
    }

    @NonNull
    @Override
    public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(),R.layout.item_recyclerview_userinfo,null);
        return new UserInfoViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder holder, int position) {

        UserInfoViewHolder userInfoViewHolder = (UserInfoViewHolder)holder;
        String title = mUserInfoList.get(position); // 获取标题名称
        ToastUtil.log(mContext,title);
        String content = Constants.getUserInfoMap().get(title); // 获取标题内容
        userInfoViewHolder.title.setText(title); // 设置标题
        userInfoViewHolder.content.setText("内容");
//        if(!content.equals("") && content != null){
            userInfoViewHolder.content.setText(content); // 设置内容
//        }else{
//            userInfoViewHolder.content.setText(""); // 设置内容
//        }
        if (title.equals("密码")){
            userInfoViewHolder.content.setTransformationMethod(PasswordTransformationMethod.getInstance());
        }
//        userInfoViewHolder.content.setTransformationMethod(HideReturnsTransformationMethod.getInstance());//显示
//        userInfoViewHolder.content.setTransformationMethod(PasswordTransformationMethod.getInstance());//隐藏
        userInfoViewHolder.itemView.setOnClickListener(view -> {
            mUserInfoOnClickListener.onItemClickListener(userInfoViewHolder.itemView,
                    title,content);
        });

    }

    @Override
    public int getItemCount() {
        return mUserInfoList.size();
    }
}
